#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:


    int calculate(string s) {
        stack<int> st;
        int i = 0, n = s.size();
        char op = '+';
        while (i < n)
        {
            while (s[i] == ' ')i++;
            if (s[i] >= '0' && s[i] <= '9')
            {
                int x = 0;
                while (i < n && s[i] >= '0' && s[i] <= '9') x = x * 10 + (s[i++] - '0');
                if (op == '+') st.push(x);
                else if (op == '-') st.push(-x);
                else if (op == '*') st.top() *= x;
                else st.top() /= x;
            }
            else
            {
                op = s[i];
                i++;
            }
        }
        long long ret = 0;
        while (!st.empty())
        {
            ret += st.top();
            st.pop();
        }
        return ret;
    }
};